using System;
using System.Collections;
using UnityEngine;

public class VersionNumber : MonoBehaviour
{
	public static string appVersion = "0.9.9";

	public string versionCheckUrl = "https://miksumortti.com/SpinTops/version-android";

	private TextMesh tMesh;

	private void Start()
	{
		tMesh = GetComponent<TextMesh>();
		CheckVersion();
	}

	public void CheckVersion()
	{
		StartCoroutine(_CheckVersion());
	}

	private IEnumerator _CheckVersion()
	{
		CoroutineWithData cd = new CoroutineWithData(this, new WWWFile().GetString(versionCheckUrl));
		yield return cd.coroutine;
		try
		{
			CompareVersion(cd.result.ToString());
		}
		catch (Exception message)
		{
			UnityEngine.Debug.LogWarning(message);
		}
	}

	private void CompareVersion(string versionString)
	{
		string[] array = versionString.Split(new char[1]
		{
			'.'
		}, StringSplitOptions.RemoveEmptyEntries);
		string[] array2 = appVersion.Split(new char[1]
		{
			'.'
		}, StringSplitOptions.RemoveEmptyEntries);
		bool flag = false;
		for (int i = 0; i < Math.Min(array.Length, array2.Length) && int.Parse(array[i]) >= int.Parse(array2[i]); i++)
		{
			if (int.Parse(array[i]) > int.Parse(array2[i]))
			{
				flag = true;
			}
		}
		if (flag)
		{
			tMesh.text = "Update: " + versionString + " available!";
			GetComponent<AudioSource>().Play();
		}
		else
		{
			base.gameObject.SetActive(value: false);
		}
	}
}
